import { defineStore } from "pinia"

export const useCountStore = defineStore("count", {
  state() {
    return {
      sum: 0,
      word: "hello",
    }
  },
  actions: {
    increment(value: number) {
      // this就是当前的store,即useCountStore
      this.sum += value
      this.word += "~"
    },
    decrement(value: number) {
      this.sum -= value
      this.word = this.word.substring(0, this.word.length - value)
    },
  },
  getters: {
    doubleSum(): number {
      return this.sum * 2
    },
    longWord: (state) => state.word + "|||||||",
  },
})
